package com.hr.followers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hr.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hr.common.annotation.Log;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.enums.BusinessType;
import com.hr.followers.domain.Followers;
import com.hr.followers.service.IFollowersService;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 关注者Controller
 * 
 * @author guan
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/manage/followers")
public class FollowersController extends BaseController
{
    @Autowired
    private IFollowersService followersService;

    /**
     * 查询关注者列表
     */
    @PreAuthorize("@ss.hasPermi('manage:followers:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUser user)
    {
        startPage();
        List<SysUser> list = followersService.selectFollowersList(user);
        return getDataTable(list);
    }

    /**
     * 获取关注者详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:followers:query')")
    @GetMapping(value = "/{followUserid}")
    public AjaxResult getInfo(@PathVariable("followUserid") Long followUserid)
    {
        return success(followersService.selectFollowersByFollowUserid(followUserid));
    }

    /**
     * 新增关注者
     */
    @PreAuthorize("@ss.hasPermi('manage:followers:add')")
    @Log(title = "关注者", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Long id)
    {
        try{
            followersService.insertFollowers(id);
            return success("添加成功");
        }
        catch (Exception e)
        {
            return error("不可重复添加");
        }

    }

    /**
     * 修改关注者
     */
    @PreAuthorize("@ss.hasPermi('manage:followers:edit')")
    @Log(title = "关注者", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Followers followers)
    {
        return toAjax(followersService.updateFollowers(followers));
    }

    /**
     * 删除关注者
     */
    @PreAuthorize("@ss.hasPermi('manage:followers:remove')")
    @Log(title = "关注者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{followUserids}")
    public AjaxResult remove(@PathVariable Long[] followUserids)
    {
        return toAjax(followersService.deleteFollowersByFollowUserids(followUserids));
    }
}
